package com.crazymaker.springcloud.message.core;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class DsShardingAlgorithm implements PreciseShardingAlgorithm<Long> {
    private final String name;
    private final int dsCounts;

    public DsShardingAlgorithm(String name, int dsCounts) {
        this.name = name;
        this.dsCounts = dsCounts;
    }

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Long> preciseShardingValue) {

        Long value = preciseShardingValue.getValue();
        long index = value % dsCounts;
        return this.name +index;
    }


}